#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<set>
using namespace std;
class Solution12
{
public:
    int maxProduct(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> dp(n + 1, 1);
        for (int i = 1;i < n + 1;i++)
        {
            dp[i] = max(dp[i - 1] * nums[i - 1], nums[i]);
        }
        int Max = dp[1];
        for (int i = 1;i < n + 1;i++) Max = max(Max, dp[i]);
        return Max;
    }
};
class Solution55
{
public:
    int getMaxLen(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> f(n + 1, 0), g(n + 1, 0);
        for (int i = 1;i < n + 1;i++)
        {
            if (i == 5)
            {
                int a = 0;
            }
            if (nums[i - 1] == 0) f[i] = g[i] = 0;
            else if (nums[i - 1] > 0)
            {
                f[i] = f[i - 1] + 1;
                if (g[i - 1] == 0)   g[i] = g[i - 1];
                else    g[i] = g[i - 1] + 1;
            }
            else
            {
                if (g[i - 1] == 0) f[i] = g[i - 1];
                else    f[i] = g[i - 1] + 1;
                g[i] = f[i - 1] + 1;
            }
        }
        int Max = f[1];
        for (int i = 1;i < n + 1;i++) Max = max(Max, f[i]);
        return Max;
    }
};
class Solution
{
public:
    bool wordBreak(string s, vector<string>& wordDict)
    {
        set<string> hash;
        set<int> begin;
        for (auto& e : wordDict) hash.insert(e);
        begin.insert(0);
        vector<int> dp(s.size());
        for (int i = 0;i < s.size();i++)
        {
            for (auto x : begin)
            {
                if (dp[i] = hash.count(s.substr(x, i - x + 1)))
                {
                    begin.insert(i + 1);
                    break;
                }
            }
        }
        return dp[s.size() - 1];
    }
};
int main()
{
    vector<int> v = { 1,2,3,5,-6,4,0,10 };
    vector<string> st = { "leet","code" };
    string str = "leetcode";
    Solution().wordBreak(str, st);
    int a = INT_MIN;
	return 0;
}